// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable restore
namespace Elastic.Clients.Elasticsearch.QueryDsl
{
	public sealed partial class IntervalsMatch : IIntervalsVariant, IIntervalsQueryVariant
	{
		[JsonInclude]
		[JsonPropertyName("analyzer")]
		public string? Analyzer { get; set; }

		[JsonInclude]
		[JsonPropertyName("filter")]
		public Elastic.Clients.Elasticsearch.QueryDsl.IntervalsFilter? Filter { get; set; }

		[JsonInclude]
		[JsonPropertyName("max_gaps")]
		public int? MaxGaps { get; set; }

		[JsonInclude]
		[JsonPropertyName("ordered")]
		public bool? Ordered { get; set; }

		[JsonInclude]
		[JsonPropertyName("query")]
		public string Query { get; set; }

		[JsonInclude]
		[JsonPropertyName("use_field")]
		public Elastic.Clients.Elasticsearch.Field? UseField { get; set; }
	}

	public sealed partial class IntervalsMatchDescriptor<TDocument> : SerializableDescriptorBase<IntervalsMatchDescriptor<TDocument>>
	{
		internal IntervalsMatchDescriptor(Action<IntervalsMatchDescriptor<TDocument>> configure) => configure.Invoke(this);
		public IntervalsMatchDescriptor() : base()
		{
		}

		private string? AnalyzerValue { get; set; }

		private Elastic.Clients.Elasticsearch.QueryDsl.IntervalsFilter? FilterValue { get; set; }

		private IntervalsFilterDescriptor FilterDescriptor { get; set; }

		private Action<IntervalsFilterDescriptor> FilterDescriptorAction { get; set; }

		private int? MaxGapsValue { get; set; }

		private bool? OrderedValue { get; set; }

		private string QueryValue { get; set; }

		private Elastic.Clients.Elasticsearch.Field? UseFieldValue { get; set; }

		public IntervalsMatchDescriptor<TDocument> Analyzer(string? analyzer)
		{
			AnalyzerValue = analyzer;
			return Self;
		}

		public IntervalsMatchDescriptor<TDocument> Filter(Elastic.Clients.Elasticsearch.QueryDsl.IntervalsFilter? filter)
		{
			FilterDescriptor = null;
			FilterDescriptorAction = null;
			FilterValue = filter;
			return Self;
		}

		public IntervalsMatchDescriptor<TDocument> Filter(IntervalsFilterDescriptor descriptor)
		{
			FilterValue = null;
			FilterDescriptorAction = null;
			FilterDescriptor = descriptor;
			return Self;
		}

		public IntervalsMatchDescriptor<TDocument> Filter(Action<IntervalsFilterDescriptor> configure)
		{
			FilterValue = null;
			FilterDescriptor = null;
			FilterDescriptorAction = configure;
			return Self;
		}

		public IntervalsMatchDescriptor<TDocument> MaxGaps(int? maxGaps)
		{
			MaxGapsValue = maxGaps;
			return Self;
		}

		public IntervalsMatchDescriptor<TDocument> Ordered(bool? ordered = true)
		{
			OrderedValue = ordered;
			return Self;
		}

		public IntervalsMatchDescriptor<TDocument> Query(string query)
		{
			QueryValue = query;
			return Self;
		}

		public IntervalsMatchDescriptor<TDocument> UseField(Elastic.Clients.Elasticsearch.Field? useField)
		{
			UseFieldValue = useField;
			return Self;
		}

		public IntervalsMatchDescriptor<TDocument> UseField<TValue>(Expression<Func<TDocument, TValue>> useField)
		{
			UseFieldValue = useField;
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			if (!string.IsNullOrEmpty(AnalyzerValue))
			{
				writer.WritePropertyName("analyzer");
				writer.WriteStringValue(AnalyzerValue);
			}

			if (FilterDescriptor is not null)
			{
				writer.WritePropertyName("filter");
				JsonSerializer.Serialize(writer, FilterDescriptor, options);
			}
			else if (FilterDescriptorAction is not null)
			{
				writer.WritePropertyName("filter");
				JsonSerializer.Serialize(writer, new IntervalsFilterDescriptor(FilterDescriptorAction), options);
			}
			else if (FilterValue is not null)
			{
				writer.WritePropertyName("filter");
				JsonSerializer.Serialize(writer, FilterValue, options);
			}

			if (MaxGapsValue.HasValue)
			{
				writer.WritePropertyName("max_gaps");
				writer.WriteNumberValue(MaxGapsValue.Value);
			}

			if (OrderedValue.HasValue)
			{
				writer.WritePropertyName("ordered");
				writer.WriteBooleanValue(OrderedValue.Value);
			}

			writer.WritePropertyName("query");
			writer.WriteStringValue(QueryValue);
			if (UseFieldValue is not null)
			{
				writer.WritePropertyName("use_field");
				JsonSerializer.Serialize(writer, UseFieldValue, options);
			}

			writer.WriteEndObject();
		}
	}

	public sealed partial class IntervalsMatchDescriptor : SerializableDescriptorBase<IntervalsMatchDescriptor>
	{
		internal IntervalsMatchDescriptor(Action<IntervalsMatchDescriptor> configure) => configure.Invoke(this);
		public IntervalsMatchDescriptor() : base()
		{
		}

		private string? AnalyzerValue { get; set; }

		private Elastic.Clients.Elasticsearch.QueryDsl.IntervalsFilter? FilterValue { get; set; }

		private IntervalsFilterDescriptor FilterDescriptor { get; set; }

		private Action<IntervalsFilterDescriptor> FilterDescriptorAction { get; set; }

		private int? MaxGapsValue { get; set; }

		private bool? OrderedValue { get; set; }

		private string QueryValue { get; set; }

		private Elastic.Clients.Elasticsearch.Field? UseFieldValue { get; set; }

		public IntervalsMatchDescriptor Analyzer(string? analyzer)
		{
			AnalyzerValue = analyzer;
			return Self;
		}

		public IntervalsMatchDescriptor Filter(Elastic.Clients.Elasticsearch.QueryDsl.IntervalsFilter? filter)
		{
			FilterDescriptor = null;
			FilterDescriptorAction = null;
			FilterValue = filter;
			return Self;
		}

		public IntervalsMatchDescriptor Filter(IntervalsFilterDescriptor descriptor)
		{
			FilterValue = null;
			FilterDescriptorAction = null;
			FilterDescriptor = descriptor;
			return Self;
		}

		public IntervalsMatchDescriptor Filter(Action<IntervalsFilterDescriptor> configure)
		{
			FilterValue = null;
			FilterDescriptor = null;
			FilterDescriptorAction = configure;
			return Self;
		}

		public IntervalsMatchDescriptor MaxGaps(int? maxGaps)
		{
			MaxGapsValue = maxGaps;
			return Self;
		}

		public IntervalsMatchDescriptor Ordered(bool? ordered = true)
		{
			OrderedValue = ordered;
			return Self;
		}

		public IntervalsMatchDescriptor Query(string query)
		{
			QueryValue = query;
			return Self;
		}

		public IntervalsMatchDescriptor UseField(Elastic.Clients.Elasticsearch.Field? useField)
		{
			UseFieldValue = useField;
			return Self;
		}

		public IntervalsMatchDescriptor UseField<TDocument, TValue>(Expression<Func<TDocument, TValue>> useField)
		{
			UseFieldValue = useField;
			return Self;
		}

		public IntervalsMatchDescriptor UseField<TDocument>(Expression<Func<TDocument, object>> useField)
		{
			UseFieldValue = useField;
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			if (!string.IsNullOrEmpty(AnalyzerValue))
			{
				writer.WritePropertyName("analyzer");
				writer.WriteStringValue(AnalyzerValue);
			}

			if (FilterDescriptor is not null)
			{
				writer.WritePropertyName("filter");
				JsonSerializer.Serialize(writer, FilterDescriptor, options);
			}
			else if (FilterDescriptorAction is not null)
			{
				writer.WritePropertyName("filter");
				JsonSerializer.Serialize(writer, new IntervalsFilterDescriptor(FilterDescriptorAction), options);
			}
			else if (FilterValue is not null)
			{
				writer.WritePropertyName("filter");
				JsonSerializer.Serialize(writer, FilterValue, options);
			}

			if (MaxGapsValue.HasValue)
			{
				writer.WritePropertyName("max_gaps");
				writer.WriteNumberValue(MaxGapsValue.Value);
			}

			if (OrderedValue.HasValue)
			{
				writer.WritePropertyName("ordered");
				writer.WriteBooleanValue(OrderedValue.Value);
			}

			writer.WritePropertyName("query");
			writer.WriteStringValue(QueryValue);
			if (UseFieldValue is not null)
			{
				writer.WritePropertyName("use_field");
				JsonSerializer.Serialize(writer, UseFieldValue, options);
			}

			writer.WriteEndObject();
		}
	}
}